package optimizer;
/**
 * Created by IntelliJ IDEA.
 * User: hasitha
 * Date: 1/25/13
 * Time: 8:51 PM
 * To change this template use File | Settings | File Templates.
 */
public class Instruction {

    private String inst, dest1, op1, op2;
    private int type;

    public Instruction(int type, String inst, String dest1, String op1, String op2) {
        // Supported types { 5, 6, 7 }
        this.inst = inst;
        this.dest1 = dest1;
        this.op1 = op1;
        this.op2 = op2;
        this.type = type;
    }

    public Instruction(int type, String inst, String dest1, String op1) {
        // Supported types { 1, 2, 4 }
        this.inst = inst;
        this.type = type;
        this.op1 = op1;
        this.op2 = "";
        this.dest1 = dest1;
    }

    public Instruction(int type, String inst, String dest1) {
        // Supported types { 3 }
        this.inst = inst;
        this.dest1 = dest1;
        this.op1 = "";
        this.op2 = "";
        this.type = type;
    }

    public String getInst() {
        return inst;
    }

    public String getDest1() {
        return dest1;
    }

    public String getOp1() {
        return op1;
    }

    public String getOp2() {
        return op2;
    }

    public int getType() {
        return type;
    }

    @Override
    public String toString() {
        String instruction = "";
        if (type == 3 || type ==0)
            instruction = inst + "\t" + dest1;
        else if (type == 1 || type == 2)
            instruction = inst + "\t" + dest1 + ",\t" + op1;
        else if (type == 4)
            instruction = inst + "\t" + op1 + ",\t" + dest1;
        else if (type == 5  || type == 7)
            instruction = inst + "\t" + dest1 + ",\t" + op1 + ",\t" + op2;

        return instruction;
    }
}
